package com.sdgakj.study.java20180827;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author: Du Ronghong
 * @Description:
 * @Date: Created in 14:44 2018/8/27
 * @Modified By:
 */
public class ThreadTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        FutureTask<String> futureTask = new FutureTask<String>(new MyThread());
        new Thread(futureTask).start();
        new Thread(futureTask).start();
        new Thread(futureTask).start();
        System.out.println(futureTask.get());

    }
}


class MyThread implements Callable<String> {

    private int ticket = 10;
    String resMsg = "票已卖完，欢迎下次再来....";

    @Override
    public String call() throws Exception {
        for (int i = 0; i < 20; i++) {
            if (this.ticket > 0) {
                System.out.println("当前票剩余：" + (ticket--));
            }
        }
        return resMsg;
    }
}
